$(function() {
	app = new Vue({
		el : '#app',
		data : {
		},
		methods : {
			saveUser : function() {
				$.ajax({
					type : "POST",
					url : '/manager/hot/sendRed',
					data : $('#form').serialize(),
					beforeSend : function() {

					},
					complete : function() {

					},
					error : function(request) {
						layer.alert("系统出错");
					},
					success : function(data) {
						if (data.status == 0) {
							refreshParentList();
							layer.alert(data.message, function() {
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						}else{
							layer.alert(data.message);
						}
					}
				});
			},
			getIdFromUrl:function(){
				var addr = location.href;
				var index = addr.lastIndexOf('/') + 1;
				var id = addr.substr(index);
				return id;
			},
			selectuser : function(id) {
				layer_show('查看', '/manager/usermanager/list/', '', '');
			},	
			init : function() {
				_self = this;
				$("#form").validate({
					rules : {
						price : {
							required : true
						},
						sendUserid : {
							required : true
						}
					},
					onkeyup : false,
					focusCleanup : true,
					success : "valid",
					submitHandler : function(form) {
						_self.saveUser();
					}
				});
			}
		}
	});
	
	app.init();
});


function closeWin() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
function resetForm() {
	$('#user-form')[0].reset();
	$("#userGroupIds").find("option").appendTo($("#userGroupIds_to"));
	$("#shopCode").html("");
}
$(function(){	
	$('#userGroupIds').multiselect({submitAllLeft: false, submitAllRight: false});

	$("#user-form").validate({
		rules:{
			name:{
				required:true,
				minlength:2,
				maxlength:16
			},
			loginName:{
				required:true,
				minlength:2,
				maxlength:16
			},
			password:{
				required:true,
				minlength:2,
				maxlength:16
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			var data = $('#user-form').serialize();
			var selectedGroups = $("#userGroupIds").find("option");
			for(var j = 0; j < selectedGroups.length; j++) {
				data += "&userGroups["+j+"]=" + $(selectedGroups[j]).prop("value");
			}
			var shopCodes = $("#shopCode").find("option");
			for(var j = 0; j < shopCodes.length; j++) {
				data += "&dataPermission[" + j + "]=" + $(shopCodes[j]).prop("value");
			}
			
			$.ajax({
			    type: "POST",
			    url: '/manager/hot/sendRed',
			    data: data,
			    beforeSend: function () {
			    	
			    },
			    complete: function () {
			    	
			    },
			    error: function(request) {
			    	layer.alert("系统出错");
			    },
			    success: function(data) {
			    	if (data.status == 0) {
			    		refreshUParentList();
						layer.alert(data.message, function() {
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						});
					}else{
						layer.alert(data.message);
					}
			    }
			});
		}
	});
});
var app = new Vue({
	  el: '#app',
	  data: {
		  roles: []
	  }
	});

getIdFromUrl:function(){
	var addr = location.href;
	var index = addr.lastIndexOf('/') + 1;
	var id = addr.substr(index);
	return id;
},


$(function() {
	//loadRoles();
});